let fs = require('fs');

// let school = {}
// function out(){
//   if(Object.keys(school).length===3){
//     console.log(school);
//   }
// }



function after(times, callback) {
  let school = {}
  return function out(key, value) {

    school[key] = value;
    if (--times === 0) {
      callback(school);
    }
  }
}
let out = after(2, (school) => {
  console.log(school);
})
//异步读写
fs.readFile('./name.txt', 'utf-8', function (err, data) {
  // school.name = data;
  // console.log(data);
  out('name', data);
})
fs.readFile('./age.txt', 'utf-8', function (err, data) {
  // school.age = data;
  // console.log(data);
  out('age', data);
})
//异步代码会等待同步代码先执行完
// 异步代码 无法使用try catch。
console.log('同步代码');